/*
 * LogMessage.cpp
 *
 *  Created on: Mar 20, 2013
 *      Author: nick
 */

#include "../h/LogMessage.h"
#include <iomanip>
#include <cstring>
#include <ctime>
#include <time.h>

using std::time;
using std::ctime;

Logging::LogMessage::LogMessage(const std::string & text, const Level severityLevel) : text(text), severityLevel(severityLevel) {
	time_t t = time(0);
	creationTime = ctime(&t);
	creationTime[strlen(creationTime) - 1] = '\0';
}

Logging::Level Logging::LogMessage::getSeverityLevel() const {
	return severityLevel;
}

void Logging::LogMessage::setSeverityLevel(const Level severityLevel) {
	this->severityLevel = severityLevel;
}

const std::string & Logging::LogMessage::getText() const {
	return text;
}

void Logging::LogMessage::setText(const std::string & text) {
	this->text = text;
}

const char* Logging::LogMessage::getCreationTime() const {
	return creationTime;
}

std::ostream & Logging::operator<<(std::ostream & out, const LogMessage & message) {
	int MAX_DATE_WIDTH = 30;
	out << std::left << std::setw(MAX_LEVEL_WIDTH) << message.getSeverityLevel() << std::left << std::setw(MAX_DATE_WIDTH) << message.getCreationTime() << message.getText() << std::endl;
	return out;
}


